
#include "stdafx.h"
#include "PathHolder.h"


CPathHolder::CPathHolder(LPDIRECT3DDEVICE9 pD3DDevice, int id)
:m_pD3DDevice(pD3DDevice),
	m_pathID(id),
	m_pMeshObject(NULL)
{
	
}



CPathHolder::~CPathHolder()
{
	Delete(m_pMeshObject);

}



void CPathHolder::SetPathMesh(const char *TextureFilePath)
{
	if (GetPathLength() <= 1)
	{
		return;
	}

	Delete(m_pMeshObject);
	m_pMeshObject = new CMesh(m_pD3DDevice);

	m_pMeshObject->InitMesh(TextureFilePath, BoundingType_Sphere);
	m_pMeshObject->SetMeshPos(GetPathBegin()->GetMeshPos());
	m_pMeshObject->SetScaleX(2.0f);
	m_pMeshObject->SetScaleY(2.0f);
	m_pMeshObject->SetScaleZ(2.0f);

	m_pMeshObject->SetVisuable(true);
	m_pMeshObject->SetIsPicked(false);

}



void CPathHolder::DeleteSelectedPathNode()
{
	for (list<CMesh>::iterator iter = m_pathList.begin();
			iter != m_pathList.end();
			++iter)
	{
		if (true == (*iter).GetIsPicked())
		{
			m_pathList.erase(iter);
			return;
		}
	}
}



void CPathHolder::AddNewPathNode(D3DXVECTOR3 newMeshPos)
{
	CMesh tempMesh(m_pD3DDevice);
	tempMesh.InitMesh("res\\mesh\\shadai.X", BoundingType_Sphere);
	tempMesh.SetMeshPos(newMeshPos);
	tempMesh.SetScaleX(2.0f);
	tempMesh.SetScaleY(2.0f);
	tempMesh.SetScaleZ(2.0f);

	tempMesh.SetVisuable(true);
	tempMesh.SetIsPicked(false);

	m_pathList.push_back(tempMesh);
}



list<CMesh>::iterator CPathHolder::GetPathBegin()
{
	return m_pathList.begin();
}



int CPathHolder::GetPathLength()
{
	return m_pathList.size();
}



void CPathHolder::RenderPath(float timeDelta)
{
	if (GetPathLength() == 0)
	{
		return;
	}

	for (list<CMesh>::iterator iter = m_pathList.begin();
		iter != m_pathList.end();
		++iter)
	{
		(*iter).Render();
	}
}
